package com.potenza.training.resume.controller;

import com.potenza.training.api.goods.ResumeBasicControllerApi;
import com.potenza.training.resume.entity.*;
import com.potenza.training.resume.feign.SysServiceFegin;
import com.potenza.training.resume.service.ResumeBasicService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 编辑个人资料
 *
 * @author lihonggang
 * @email lihonggang@gmail.com
 * @date 2021-07-15 15:52:55
 */
@RestController
@RequestMapping("resume/resumebasic")
public class ResumeBasicController implements ResumeBasicControllerApi {
    @Autowired
    private ResumeBasicService resumeBasicService;

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Autowired
    SysServiceFegin sysServiceFegin;

    @GetMapping("finduid")
    public void finduid(){
        R info = sysServiceFegin.info();
        System.out.println(info.get("user")+"99999999999");

    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("resume:resumebasic:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = resumeBasicService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("resume:resumebasic:info")
    public R info(@PathVariable("id") Long id){
		ResumeBasicEntity resumeBasic = resumeBasicService.getById(id);

        return R.ok().put("resumeBasic", resumeBasic);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("resume:resumebasic:save")
    public R save(@RequestBody ResumeBasicEntity resumeBasic){
        R info = sysServiceFegin.info();
        Map map = (Map) info.get("user");
        resumeBasic.setStatus(0);
        resumeBasic.setUid(Integer.parseInt(map.get("userId").toString()));
		resumeBasicService.save(resumeBasic);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("resume:resumebasic:update")
    public R update(@RequestBody ResumeBasicEntity resumeBasic){
		resumeBasicService.updateById(resumeBasic);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("resume:resumebasic:delete")
    public R delete(@RequestBody Long[] ids){
		resumeBasicService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 发送短信验证码
     */
    @RequestMapping("/send/{phone}")
    @RequiresPermissions("resume:resumebasic:send")
    public R sendMessage(@PathVariable String phone){
        rabbitTemplate.convertAndSend("gll_queue",phone);
        return R.ok();
    }

    /**
     * 修改手机号
     */
    @GetMapping("/updatePhone/{phone}/{code}")
    @RequiresPermissions("resume:resumebasic:updatePhone")
    public R updatePhone(@PathVariable String phone,
                         @PathVariable String code){
        return resumeBasicService.updatePhone(phone,code);
    }

//    @GetMapping("/findResumeByUid/{uid}")
//    public ResumeBasicEntity findResumeByUid(@PathVariable Integer uid){
//        return resumeBasicService.findResumeByUid(uid);
//    }
    @GetMapping("/findResumeByUid")
    public ResumeBasicEntity findResumeByUid(){
        R info = sysServiceFegin.info();
        Map map = (Map) info.get("user");
        System.out.println(map.get("userId"));
        return resumeBasicService.findResumeByUid(Long.parseLong(map.get("userId").toString()));
    }
    @GetMapping("/findResumeByClazzId/{clazzId}")
    public List<ResumeBasicEntity> findResumeByClazzId(@PathVariable Integer clazzId){
        return resumeBasicService.findResumeByClazzId(clazzId);
    }

    @GetMapping("/findAll/{resumeId}")
    //@RequiresPermissions("resume:resumebasic:info")
    public R info(@PathVariable  int resumeId){
        //基本信息
        ResumeBasicEntity resumeBasicEntity  =resumeBasicService.findResumeBasic(resumeId);
      //优势
       List<AdvantageEntity> advantageEntityList= resumeBasicService.findAdvange(resumeId);
       //工作经历
      List<WorkExperienceEntity> workExperienceEntityList=  resumeBasicService.findWorkExpersoin(resumeId);
      //求职期望
        List<ResumeHope> resumeHopeList=resumeBasicService.findResumeHope(resumeId);
        //教育经历
        List<EducationExperienceEntity> educationExperienceEntityList=resumeBasicService.findEducation(resumeId);
        //项目经历
        List<ItemExperienceEntity> itemExperienceEntityList=resumeBasicService.findItem(resumeId);
        //社交作品
        List<SocialEntity> socialEntityList=resumeBasicService.findSocial(resumeId);
        //简历状态
        ExamineEntity examineEntity=resumeBasicService.findExamine(resumeId);

        //图片
        List<ImageEntity> imageEntityList=resumeBasicService.findImage(resumeId);
        return R.ok().put("resumeBasic", resumeBasicEntity).put("advantage",advantageEntityList)
                .put("work",workExperienceEntityList)
                .put("hope",resumeHopeList)
                .put("education",educationExperienceEntityList)
                .put("item",itemExperienceEntityList)
                .put("socil",socialEntityList)
                .put("image",imageEntityList)
                .put("examine",examineEntity);


        //return R.ok();
    }

    @GetMapping("updateStatus")
    public R updateStatus(Integer id,String status,String reason,String image) throws Exception {

        return resumeBasicService.updateStatus(id,status,reason,image);
    }


}
